
class Option(object):
	"""
	Global singleton. It acts as a global storage for user options.
	
	Preferred usage is:
		>>> Option().key=value # Setter
		>>> print Option().key # Getter

	If you want to check Option object against existence of an option, use:
		>>> if 'key' in Option()
	"""
	def __new__(self):
		if not '_instance' in self.__dict__:
			self._instance = object.__new__(self)
		return self._instance
	def __contains__(self,x):
		if x in dir(self):
			return True
		else:	return False

class Private(object):
	"""
	Global singleton. Only for internal use. Technically, it works exactly as Option object.
	"""
	def __new__(self):
		if not '_instance' in self.__dict__:
			self._instance = object.__new__(self)
		return self._instance
	def __contains__(self,x):
		if x in dir(self):
			return True
		else:	return False

class Log(object):
	"""
	Global singleton. It acts as a global logging facility. It's used to cache
	compiled files checksums and installation logs. Logs usually go to file named
	.buildpy.log

	Log object is in fact modified version of Option object with a few added methods.
	"""
	data={}
	def __new__(self):
		if not '_instance' in self.__dict__:
			self._instance = object.__new__(self)
			self._instance.load()
		return self._instance
	def save(self):
		"""Saves logs to log file"""
		f=open('.buildpy.log','w+')
		pickle.dump(self.data,f)
		f.close()
	def load(self):
		"""Loads logs from log file."""
		if not os.path.exists('.buildpy.log'):
			return
		f=open('.buildpy.log')
		self.__dict__['data']=pickle.load(f)
		f.close()
	def reset(self):
		"""Resets log data"""
		self.data={}
	def __setattr__(self,attr,key,*unexpected):
		self.data[attr]=key
	def __getattr__(self,attr,*unexpected):
		return self.data[attr]
	def __contains__(self,x):
		if x in self.data:
			return True
		else:	return False
